package ch.zhaw.skuh.turing.view;

import java.awt.Container;

import javax.swing.BoxLayout;
import javax.swing.JFrame;

import ch.zhaw.skuh.turing.controller.Controller;
import ch.zhaw.skuh.turing.model.turingmaschine.TuringChar;

public class GUI {
	private JFrame frame;
	private ControlPanel controlPanel;
	private OutputPanel outputPanel;
	private TuringChar turingChar;

	public GUI(Controller ctr) {
		frame = new JFrame("Turing-Tape");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		Container container = frame.getContentPane();
		container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));

		this.controlPanel = new ControlPanel(ctr);

		container.add(this.controlPanel);
		frame.setSize(frame.getMaximumSize());
		setVisible();
	}
	
	public void setOutputPanel(TuringChar tc, long time){
		if(this.turingChar==tc){
			outputPanel.update(time);
		} else{
			this.turingChar=tc;
			if (outputPanel != null) {
				frame.getContentPane().remove(outputPanel);
			}
			this.outputPanel = new OutputPanel(tc);
			frame.getContentPane().add(outputPanel);
		}
	}

	public void setVisible() {
		frame.setSize(frame.getWidth(), frame.getHeight());
		frame.setVisible(true);
	}

	public final ControlPanel getControlPanel() {
		return controlPanel;
	}
	
	

}